package myLucene;

import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldSelectorResult;
import org.apache.lucene.document.Field.Index;

public class DocumentIndex {
	/**
	 * makes lucene document given the Dewac Corpus
	 * 
	 * @param string
	 *            : Dewac Corpus line by line each line contains a word, a
	 *            pos-tag, junk-tag
	 * @return doc : the indexed document
	 * @throws Exception 
	 */
	public static Document DeWacDoc(String string, Document doc) throws Exception {
		// Document doc = new Document();
		String[] items = string.split(" ");

//		if (string.isEmpty()) {
//			// the content to then index termVector
//			// maybe NOT_ANALYZED_NO_NORMS!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
//			Field content = new Field("content", "<eof>", Field.Store.YES,
//					Field.Index.NOT_ANALYZED,
//					Field.TermVector.WITH_POSITIONS_OFFSETS);
//			doc.add(content);
//			Field pos = new Field("pos", "$.", Field.Store.YES,
//					Field.Index.NOT_ANALYZED,
//					Field.TermVector.WITH_POSITIONS_OFFSETS);
//			doc.add(pos);
//			Field lemma = new Field("lemma", ".", Field.Store.YES,
//					Field.Index.NOT_ANALYZED,
//					Field.TermVector.WITH_POSITIONS_OFFSETS);
//			doc.add(lemma);
//			Field index = new Field("index", "11481283", Field.Store.YES,
//					Field.Index.NOT_ANALYZED,
//					Field.TermVector.WITH_POSITIONS_OFFSETS);
//			doc.add(index);
//
//		}
		if (items.length == 4) {
			// System.out.println("!!!!: "+items[0]);
			Field content = new Field("content", items[0], Field.Store.YES,
					Field.Index.NOT_ANALYZED,
					Field.TermVector.WITH_POSITIONS_OFFSETS);
			doc.add(content);
//			Field pos = new Field("pos", items[1], Field.Store.YES,
//					Field.Index.NOT_ANALYZED,
//					Field.TermVector.WITH_POSITIONS_OFFSETS);
//			doc.add(pos);
			Field lemma = new Field("lemma", items[2], Field.Store.YES,
					Field.Index.NOT_ANALYZED,
					Field.TermVector.WITH_POSITIONS_OFFSETS);
			doc.add(lemma);
			Field index = new Field("index", items[3], Field.Store.YES,
					Field.Index.NOT_ANALYZED,
					Field.TermVector.WITH_POSITIONS_OFFSETS);
			doc.add(index);

		}
//		if(items.length!=4&&!string.isEmpty()){
//			throw new Exception(DocumentIndex.class.getName()+" not well formed: "+string);
//		}

		return doc;
	}
}
